/*
 * Timothy Daniel Bowden
 * checkHand function
 * Input:  The hand to examine (a size 5 array of Cards)
 * Output: An integer representation of the hand.
 * Elements returned:	(in order)
 *	(0)Royal Flush		(A,K,Q,J,10 all same suit)
 *	(1)Straight Flush	(Any 5 consecutive cards same suit)
 *	(2)Four of a Kind	(4 cards same value)
 *	(3)Full House		(3 of a kind and 2 of a kind in same hand)
 *	(4)Flush			(All 5 cards same suit)
 *	(5)Straight			(Any 5 consecutive cards)
 *	(6)Three of a Kind	(3 cards same value)
 *	(7)Two Pair			(2 sets of 2 cards same value)
 *	(8)Jacks or Better	(2 Jacks or higher value pair)
 *	(9)Nothing.			(None of the above)
 */

public class checkHand {		// Doesn't need a class. I'm thinking this should be a method of another class.(Player or Game maybe?)

	public checkHand(Card[] hand) {
		int[] values = new int[52];
		int[] suits = new int[4];
		
		for(int i = 0; i < 5; i++) {
			values[hand.value] = hand.value;
			suits[hand.suit] = hand.suit;
		}

	}
	public boolean isRoyalFlush() {
		return false;
	}
	public boolean isStraightFlush() {
		if(isStraight() && isFlush()) return true;
		return false;
	}
	public static boolean isFourKind() {
		int k = 0;
		//Cycle through hand and check each card against the others.
		for(int i = 0; i < hand.length; i++) {
			for(int j = 0; j < hand.length; j++) {
				if(hand[i].v.equals(hand[j].v)) {
					// Increment count of matches if the cards are the same.
					k++;
				}
			}
		}
		// Four matches = Four of a Kind. Return true.
		if(k == 4) return true;
		// Not four matches. Return false.
		return false;
	}
	public static boolean isFullHouse() {	//INCOMPLETE
		// Full house is a similar setup to Four of a Kind. Rule that option out.
/* 			if(isFourKind()) return false;
		
		int k = 0;
		int l = 0;
		for(int i = 0; i < hand.length; i++) {
			for(int j = 0; j < hand.length; j++) {
				if(hand[i].v.equals(hand[j].v))
			}
		} */
	}
	public static boolean isFlush() { //NEED TO CHANGE FOR SUITS NOT VALUES
		boolean test = true;
		for(int i = 0; i < hand.length; i++) {
			for(int j = 0; j < hand.length; j++) {
				if(test && (hand[i].s == hand[j].s)) {
					test = true;
				}
				else test = false;
			}
		}
		return test;
	}
	public static boolean isStraight() {
		int currentPos = 0;
		int temp = 0;
		
		// Cycle through hand.
		for(int i = 1; i < hand.length; i++) {
			currentPos = i;
			// Sort array by order of card value.
			while(currentPos != 0) {
				if(hand[pos].v < hand[pos-1].v) {
					temp = hand[pos].v;
					hand[pos].v = hand[pos-1].v;
					hand[pos-1].v = temp;
				}
				pos--;
			}
		}
		// Check that cards are exactly 1 off from each other (meaning a straight.
		for(int i = 0; i < hand.length - 1; i++) {
			// Return false if they aren't.
			if(hand[i].v != hand[i+1].v - 1) return false;
		}
		// Return true if they are.
		return true;
	}
	public static boolean isThreeKind() {
		// Similar setup to other hands.  Rule them out.
		if(isFourKind() || isFullHouse()) return false;
		
		int k = 0;
		// Cycle through hand and compare card values to each other.
		for(int i = 0; i < hand.length; i++) {
			for(int j = 0; j < hand.length; j++) {
				// Increment count of matches if cards have the same value.
				if(hand[i].v.equals(hand[j].v)) {
					k++;
				}
			}
		}
		// Three matches = Three of a Kind. Return true.
		if(k == 3) return true;
		// Return false otherwise.
		return false;
	}
	public static boolean isTwoPair() { // NEEDS TESTING
		// Rule out similar hands.
		if(isFourKind() || isThreeKind() || isFullHouse()) return false;
		
		int k = 0;
		int l = 0;
		// Cycle through hand and compare card values to each other.
		for(int i = 0; i < hand.length; i++){
			for(int j = 0; j < hand.length; j++){
				// Add to count if values match.
				if(hand[i].v.equals(hand[j].v)){
					k++;
				}
			}
			// To account for more than one pair.
			if(k > 1)
				l++;
		}
		// Total sum of matches is 4 = Two Pair. Return true.
		if(l == 4) return true;
		// Otherwise return false.
		return false;
	}
	public static boolean isJackBetter() {
		if(isFourKind() || isThreeKind() || isFullHouse() || isTwoPair()) return false;
		// Need to add test that cards are jack value or higher.  As is it just checks for a normal pair of cards.
		for(int i = 0; i < hand.length; i++) {
			for(int j = 0; j < hand.length; j++) {
				if(hand[i].v.equals(hand[j].v)) {
					k++;
				}
			}
		}
		if(k == 2) return true;
		return false;
	}
}